package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Drivers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PublicPrice;
import com.ruoyi.system.service.IPublicPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品价格Controller
 * 
 * @author he
 * @date 2025-08-13
 */
@Api(tags = "价格接口")
@RestController
@RequestMapping("/system/price")
public class PublicPriceController extends BaseController
{
    @Autowired
    private IPublicPriceService publicPriceService;

    /**
     * 查询商品价格列表
     */
    @ApiOperation("查询价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicPrice publicPrice)
    {
        startPage();
        List<PublicPrice> list = publicPriceService.selectPublicPriceList(publicPrice);
        return getDataTable(list);
    }

    @ApiOperation("查询价格商品下拉框信息")
    @PostMapping("/getGoodsPriceInfoList")
    public TableDataInfo getGoodsInfoList(@RequestParam(value = "paramName", required = false) String paramName)
    {
        List<Drivers> list = publicPriceService.getGoodsPriceInfoList(paramName);
        return getDataTable(list);
    }

    /**
     * 导出商品价格列表
     */
    @ApiOperation("导出价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:export')")
    @Log(title = "商品价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PublicPrice publicPrice)
    {
        List<PublicPrice> list = publicPriceService.selectPublicPriceList(publicPrice);
        ExcelUtil<PublicPrice> util = new ExcelUtil<PublicPrice>(PublicPrice.class);
        util.exportExcel(response, list, "商品价格数据");
    }

    /**
     * 获取商品价格详细信息
     */
    @ApiOperation("查询商品价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(publicPriceService.selectPublicPriceById(id));
    }

    /**
     * 新增商品价格
     */
    @ApiOperation("新增商品价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:add')")
    @Log(title = "商品价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicPrice publicPrice)
    {
        return toAjax(publicPriceService.insertPublicPrice(publicPrice));
    }

    /**
     * 修改商品价格
     */
    @ApiOperation("修改商品价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:edit')")
    @Log(title = "商品价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicPrice publicPrice)
    {
        return toAjax(publicPriceService.updatePublicPrice(publicPrice));
    }

    /**
     * 删除商品价格
     */
    @ApiOperation("删除商品价格信息")
    @PreAuthorize("@ss.hasPermi('system:price:remove')")
    @Log(title = "商品价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(publicPriceService.deletePublicPriceByIds(ids));
    }
}
